//
//  ZVieoHeadView.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/22.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZVieoHeadView.h"
#import "ZDoctorView.h"

@interface ZVieoHeadView () <ZFPlayerDelegate>{
    ZDoctorView * _doctorView;
}
;
@end
@implementation ZVieoHeadView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initlizeInterface];
    }
    return self;
}

- (void)initlizeInterface {
    __weak typeof(self) weakSelf = self;
    [self addSubview:self.playerFatherView];
    _doctorView = [[ZDoctorView alloc] init];
    _doctorView.backgroundColor = [UIColor whiteColor];
    _doctorView.GoDoctorVCBlock = ^() {
        [weakSelf jumpDotorVC];
    };
    self.playerView = [[ZFPlayerView alloc]init];
    [self addSubview:_doctorView];
    [_doctorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.equalTo(self);
        make.top.equalTo(self.playerFatherView.mas_bottom);
        make.height.offset(65*ysIZE);
    }];
    [self.playerFatherView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.top.equalTo(self);
        make.height.offset(210*ysIZE);
    }];
    
   
}
- (void)setUrlString:(NSString *)urlString {
    _urlString = urlString;
    self.playerModel.videoURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IconURL,urlString]];
    [self.playerView playerControlView:nil playerModel:self.playerModel];
    // 设置代理
    self.playerView.delegate = self;
    // 打开预览图
    self.playerView.hasPreviewView = YES;
    // 是否自动播放，默认不自动播放
//    [self.playerView autoPlayTheVideo];
}
- (void)beginVideo {
    [self.playerView play];
}
- (void)suspendVideo {
    [self.playerView pause];
}
- (void)setZdModel:(ZDoctorTModel *)zdModel {
    _zdModel = zdModel;
    _doctorView.dModel = zdModel;
}
- (void)jumpDotorVC {
    if (self.ZVHDelegate &&[self.ZVHDelegate conformsToProtocol:@protocol(ZVieoHeadViewDelegate)] ) {
        [self.ZVHDelegate jionDotroVC];
    }
}
- (UIView *)playerFatherView {
    if (_playerFatherView) {
        return _playerFatherView;
    }
    _playerFatherView = [[UIView alloc] init];
    return _playerFatherView;
}
- (ZFPlayerModel *)playerModel {
    if (_playerModel ) {
        return _playerModel;
    }
    _playerModel = [[ZFPlayerModel alloc] init];
    _playerModel.title = @"";
    _playerModel.videoURL = [NSURL URLWithString:@""];
    _playerModel.placeholderImage = [UIImage imageNamed:@"loading_bgView1"];
    _playerModel.fatherView       = self.playerFatherView;
    return _playerModel;
}

@end
